﻿<!DOCTYPE HTML>
<html>
{include file="public:header_css"}
<link href="__STATIC__/admin/lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />
<body>

<nav class="breadcrumb">
	<i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 营销管理 <span class="c-gray en">&gt;</span> 编辑增值服务
	<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>

<div class="page-container">

	<div action="" method="post" class="form form-horizontal" id="form-shops-add" enctype="multipart/form-data">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>主菜单名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$info['primary_menu']}" placeholder="" id="primary_menu" style="width:22%;">
			</div>
		</div>

		{foreach name="info.sub_menu" item="val" key="key"}
		<div class="row cl" id="sub">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>子菜单名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$val[0]}" id="sub_menu{$key+1}" style="width:22%;">&nbsp;&nbsp;
				<span class="c-red">*</span>控制器/方法名：&nbsp;&nbsp;<input type="text" class="input-text" value="{$val[1]}" id="sub_control{$key+1}" style="width:22%;">&nbsp;&nbsp;&nbsp;
				{if $key==0}
				<button class="btn btn-primary radius" type="button" id="tianjia" onclick="add_sub('{$key+1}')" >&nbsp;&nbsp;添加&nbsp;&nbsp;</button>
				{else /}
				{/if}
			</div>
		</div>
		{/foreach}

		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>费用：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$info['price']}" placeholder="" id="price" style="width:22%;" >&nbsp;元
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>有效期：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$info['period_validity']}" placeholder="" id="period_validity" style="width:22%;" >&nbsp;天
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<input type="hidden" id="id" value="{$info['id']}">
				<button class="btn btn-primary radius" type="submit" id="submit">&nbsp;&nbsp;提交&nbsp;&nbsp;</button>
				<a class="btn btn-warning radius" href="{:url('index')}">&nbsp;&nbsp;取消&nbsp;&nbsp;</a>
			</div>
		</div>
	</div>

</div>
{include file="public:footer_js"}

<script type="text/javascript" src="__STATIC__/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="__STATIC__/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__STATIC__/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__STATIC__/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">

    var count = {$count};
    function add_sub(){

        var sub_menu	 = $("#sub_menu1").val();
        var sub_control	 = $("#sub_control1").val();
        count=count+1;

        if (sub_menu=="" || sub_control=="") {
            layer.msg('请填写完整的子菜单!',{icon:7,time:1000});
            return;
        }

        //清除
        $("#sub_menu1").val('');
        $("#sub_control1").val('');

        $("#sub").after("<div class=\"row cl\" id=\"sub\">\n" +
            "<label class=\"form-label col-xs-4 col-sm-3\"><span class=\"c-red\">*</span>子菜单名称：</label>\n" +
            "<div class=\"formControls col-xs-8 col-sm-9\">\n" +
            "<input type=\"text\" class=\"input-text\" value='"+sub_menu+"' id=\"sub_menu"+count+"\" style=\"width:22%;\">&nbsp;&nbsp;\n" +
            "<span class=\"c-red\">*</span>控制器/方法名：&nbsp;&nbsp;<input type=\"text\" class=\"input-text\" value='"+sub_control+"' placeholder=\"\" id=\"sub_control"+count+"\" style=\"width:22%;\">&nbsp;&nbsp;&nbsp;&nbsp;\n" +
            "</div>\n" +
            "</div>");
    }
    $("#submit").click(function(){

        var arr_sub  = [];
        for (var i=1;i<=count;i++){
            var sub_menu	 = $("#sub_menu"+i).val();
            var sub_control	 = $("#sub_control"+i).val();
            if (sub_menu!='' && sub_control!=''){
                var sub_item = sub_menu+"&"+sub_control;
                arr_sub.push(sub_item);
            }
        }

        var primary_menu    = $("#primary_menu").val();
        var price           = $("#price").val();
        var period_validity = $("#period_validity").val();
        var id = $("#id").val();

        // 主菜单
        if(primary_menu == ''){
            layer.msg('主菜单不可为空!',{icon:7,time:1000});
            $("#primary_menu").focus();
            return ;
        }

        if (arr_sub.length<=0){
            layer.msg('子菜单不可为空!',{icon:7,time:1000});
            $("#sub_menu1").focus();
            return ;
        }

        //异步提交数据
        $.ajax({
            type:"POST",
            url:"{:url('edit')}",
            data:{
                id :id,
                primary_menu : primary_menu,
                arr_sub : JSON.stringify(arr_sub),
                price : price,
                period_validity : period_validity
            },
            async:true,
            success:function (res) {
                if(res.code === 0){
                    layer.msg(res.msg,{icon:5,time:2000});
                }else{
                    layer.msg(res.msg,{icon:6,time:2000});
                    setTimeout(
                        function(){
                            location.replace("{:url('index')}");
                        },
                        1000
                    );
                }
            }
        });

    });


    //置空
    function reset() {
        //清除
        $("#sub_menu1").val('');
        $("#sub_control1").val('');
    }
    function remove() {
        alert("11");
        //清除
        $("#sub_menu").val('');
        $("#sub_control").val('');
    }
</script>

</body>
</html>